home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / tpb4_src.zip / CORE2.PAS < prev    next >
Pascal/Delphi Source File  |  1988-09-13  |  22KB  |  865 lines

  1. { TPBoard 4.2 Copyright (c) 1987,88 by Jon Schneider & Rick Petersen  
  2.   Portions Copyright (c) 1986,87 by Steve Fox and Les Archambault  
  3.   
  4.   Last modified  ::  9-13-88 7:09 pm 
  5. }
  6.  
  7. {$R-}                             {Range checking off}
  8. {$B-}                             {Boolean complete evaluation off}
  9. {$S-}                             {Stack checking off}
  10. {$I+}                             {I/O checking on}
  11. {$N-}                             {No numeric coprocessor}
  12.  
  13. Unit Core2;
  14.  
  15. Interface
  16.  
  17. Uses
  18.   TPCrt, Globals, TPSTRING, Core1,
  19.   KeyStuff, BinEd, Sort;
  20.   
  21.   
  22. procedure GetStr(var inpstr      : StrStd;
  23.                  var ch          : Char;
  24.                  maxlen          : Integer;
  25.                  mode            : Str10);
  26.                  
  27. procedure pause;
  28.  
  29. function prompt(pr : StrStd; len : Integer; mode : Str10) : StrStd;
  30.  
  31. function ask(pr : StrPr; mode : Char) : Boolean;
  32.  
  33. function test_bit(var num; bit_num : Integer) : Boolean;
  34.  
  35. procedure set_bit(var target; bit_num : Integer);
  36.  
  37. procedure clear_bit(var target; bit_num : Integer);
  38.  
  39. procedure FindSect(var req : DosFileName; var drive : Str3; var found : Boolean);
  40.  
  41. function min(x, y : LongInt) : Integer;
  42.  
  43. function max(x, y : Integer) : Integer;
  44.  
  45. function intstr(n, w : Integer) : Str10;
  46.  
  47. function strint(st : Str10)     : Integer;
  48.  
  49. function FormTAD(t : tad_array)  : StrTAD;
  50.  
  51. procedure send_time(size : Integer; var mm, ss : Integer);
  52.  
  53. procedure timer(var time_on, time_left : Integer);
  54.  
  55. procedure mesg_insert(TypMsg : Byte);
  56.  
  57. procedure list(ch : Char);
  58.  
  59. procedure Write_status_line;
  60.  
  61. procedure caps_to_mixed(var full_name : StrStd);
  62.  
  63. procedure ScrollOn;
  64.  
  65. procedure ScrollOff;
  66.  
  67. procedure NewExit;
  68.  
  69. function greg_to_jul(day, mon, yr : Integer) : Real;
  70.  
  71. procedure check_time;
  72.  
  73. procedure UserEventCheck(EventNo, KbdFlagInfo : Word);
  74.  
  75. procedure put_recs;
  76.  
  77. procedure get_recs;
  78.  
  79. function less_rec(var x, y : sort_typ) : Boolean;
  80.  
  81.  
  82.   {==========================================================================}
  83.   
  84.   
  85. Implementation
  86.  
  87.  
  88.   procedure GetStr(var inpstr      : StrStd;
  89.                    var ch          : Char;
  90.                    maxlen          : Integer;
  91.                    mode            : Str10);
  92.     { Get a valid input string from the user }
  93.     
  94.   type
  95.     charset         = set of Char;
  96.     
  97.   const
  98.     editset : charset = [BS, RUB, CAN, TAB];
  99.     termset : charset = [LF, CR, ETX];
  100.     dispset : charset = [' '..'~'];
  101.     
  102.   var
  103.     auto, echo, shift_lock, Wrap, question, hard : Boolean;
  104.     i, len, cursor  : Integer;
  105.     
  106.   begin
  107.     if user_rec.columns < maxlen then
  108.       maxlen := user_rec.columns;
  109.     auto := (Pos('A', mode) > 0); { Line complete when full }
  110.     echo := (Pos('E', mode) > 0); { Display characters on entry }
  111.     shift_lock := (Pos('S', mode) > 0); { Make all characters upper case }
  112.     Wrap := (Pos('W', mode) > 0);
  113.     question := (Pos('?', mode) > 0); { Force inpstr := '?' when encountered }
  114.     hard := (Pos('H', mode) > 0);
  115.     auto := auto or Wrap;         { Wrap forces auto on }
  116.     len := Length(inpstr);
  117.     cursor := Succ(len);
  118.     if echo and (cursor > 0) then
  119.       Write(com, inpstr);
  120.     repeat
  121.       input_time := timeout*18.2;
  122.       time_count := 0;
  123.       repeat
  124.         ch := GetChar;
  125.       until (not Online) or (ch <> NUL) or (input_timeout);
  126.       if shift_lock then
  127.         ch := Upcase(ch);
  128.       case ch of
  129.         TAB :
  130.           repeat
  131.             if echo then
  132.               Write(com, ' ');
  133.             Inc(cursor);
  134.             Insert(' ', inpstr, cursor)
  135.           until (0 = cursor mod 5) or (cursor >= maxlen);
  136.         RUB, BS :
  137.           if cursor > 1 then
  138.             begin
  139.               Write(com, BS, ' ', BS);
  140.               cursor := Pred(cursor);
  141.               Delete(inpstr, cursor, 1)
  142.             end;
  143.         CAN :
  144.           while cursor > 1 do
  145.             begin
  146.               Write(com, BS, ' ', BS);
  147.               cursor := Pred(cursor);
  148.               Delete(inpstr, cursor, 1)
  149.             end;
  150.         ^A :
  151.           while cursor > 1 do
  152.             begin
  153.               if echo then
  154.                 Write(com, BS);
  155.               cursor := Pred(cursor)
  156.             end;
  157.         ^S :
  158.           if cursor > 1 then
  159.             begin
  160.               if echo then
  161.                 Write(com, BS);
  162.               cursor := Pred(cursor)
  163.             end;
  164.         ^D :
  165.           if cursor <= Length(inpstr) then
  166.             begin
  167.               if echo then
  168.                 Write(com, inpstr[cursor]);
  169.               Inc(cursor)
  170.             end;
  171.         ^F :
  172.           while cursor <= Length(inpstr) do
  173.             begin
  174.               if echo then
  175.                 Write(com, inpstr[cursor]);
  176.               Inc(cursor)
  177.             end;
  178.         ^G :
  179.           if cursor <= Length(inpstr) then
  180.             Delete(inpstr, cursor, 1);
  181.       else
  182.         if (ch in dispset) and ((len < maxlen) or auto) then
  183.           begin
  184.             if echo then
  185.               Write(com, ch)
  186.             else
  187.               Write(com, '.');
  188.             if (ch = '?') and question and (len = 1) then
  189.               begin
  190.                 inpstr := ch;
  191.                 ch := CR
  192.               end
  193.             else
  194.               begin
  195.                 Insert(ch, inpstr, cursor);
  196.                 Inc(cursor)
  197.               end
  198.           end
  199.       end;
  200.       len := Length(inpstr)
  201.     until (not Online) or (ch in termset) or ((len >= maxlen) and auto);
  202.     next_inpstr := '';
  203.     if Wrap and (len >= maxlen) then
  204.       begin
  205.         while (inpstr[len] <> ' ') and (len > 1) do
  206.           len := Pred(len);
  207.         if len > 1 then
  208.           begin
  209.             if echo then
  210.               begin
  211.                 for i := Succ(len) to Length(inpstr) do
  212.                   Write(com, BS);
  213.                 for i := Succ(len) to Length(inpstr) do
  214.                   Write(com, ' ')
  215.               end;
  216.             next_inpstr := Copy(inpstr, Succ(len), Length(inpstr));
  217.             inpstr := Copy(inpstr, 1, Pred(len))
  218.           end;
  219.       end
  220.     else if hard and (Length(inpstr) > 0) then
  221.       inpstr := inpstr+Chr($0D)+Chr($0A);
  222.   end;
  223.   
  224.   
  225.   procedure pause;
  226.     { Pause for user response before continuing }
  227.     
  228.   var
  229.     ch              : Char;
  230.     
  231.   begin
  232.     input_time := timeout*18.2;
  233.     time_count := 0;
  234.     Write(com, 'Press any key to continue...');
  235.     if user_rec.noisy then
  236.       Write(com, BEL);
  237.     repeat
  238.       ch := GetChar;
  239.       if (ch = ETX) or (ch = #$0B) or (Upcase(ch) = 'K') or (ch = ESC) then
  240.         abort := True;
  241.     until (not Online) or (ch <> NUL) or (input_timeout);
  242.     Write(com, CR, ' ':28, CR)
  243.   end;
  244.   
  245.   
  246.   
  247.   function prompt(pr : StrStd; len : Integer; mode : Str10) : StrStd;
  248.     { Prompt user, return string and process multiple command buffer }
  249.     
  250.   type
  251.     charset         = set of Char;
  252.     
  253.   const
  254.     delim_set : charset = [';', ' ', ','];
  255.     
  256.   var
  257.     i, J            : Integer;
  258.     reply, Buffer   : StrStd;
  259.     t               : tad_array;
  260.     
  261.   begin
  262.     reply := '';
  263.     Buffer := '';
  264.     ch := ' ';
  265.     if (not mult_cmds) or (Pos('L', mode) > 0) then {L for literal}
  266.       begin
  267.         Write(com, pr);
  268.         if Pos('M', mode) > 0 then
  269.           Write(com, ' [press "?" for menu]');
  270.         Write(com, '> ');
  271.         if user_rec.noisy then
  272.           Write(com, BEL);
  273.         GetStr(Buffer, ch, len, mode);
  274.       end
  275.     else
  276.       Buffer := Cmd_Queue;        {feed in from queue}
  277.     if Pos('L', mode) = 0 then
  278.       begin                       {not literal, process mult. commands}
  279.         i := 0;
  280.         J := 0;
  281.         repeat
  282.           Inc(i);
  283.           if (Pos('N', mode) > 0) and (Buffer[i] = ' ') then
  284.             Inc(i);
  285.           if Buffer[i] in delim_set then
  286.             J := i;
  287.         until (i >= Length(Buffer)) or (Buffer[i] in delim_set);
  288.         if J > 0 then
  289.           begin
  290.             mult_cmds := True;
  291.             reply := Copy(Buffer, 1, J-1); {get command from buffer}
  292.             Delete(Buffer, 1, J); {remove cmd and delimeter}
  293.             if Buffer = '' then
  294.               begin
  295.                 mult_cmds := False;
  296.                 Cmd_Queue := '';
  297.               end
  298.             else
  299.               Cmd_Queue := Buffer; {save balance for next command}
  300.             if reply = '' then
  301.               reply := ' ';
  302.             if macro_in_progress and (reply = Chr(13)) then
  303.               reply := ' ';
  304.           end
  305.         else
  306.           begin
  307.             mult_cmds := False;
  308.             Cmd_Queue := '';
  309.             reply := Buffer;      {for single commands}
  310.             if reply = '' then
  311.               reply := ' ';       {so we wont bomb ch assignments}
  312.             if macro_in_progress and (reply = Chr(13)) then
  313.               reply := ' ';
  314.           end;
  315.         if macro_in_progress then
  316.           Delay(500);
  317.       end                         {not literal}
  318.     else
  319.       begin                       {literal}
  320.         reply := Buffer;
  321.         mult_cmds := False;
  322.         Cmd_Queue := '';
  323.       end;
  324.     WriteLn(com);
  325.     prompt := reply;
  326.   end;                            {prompt}
  327.   
  328.   
  329.   
  330.   function ask(pr : StrPr; mode : Char) : Boolean;
  331.     { Ask yes-or-no question and return TRUE for 'Y', FALSE otherwise }
  332.     
  333.   var
  334.     ch              : Char;
  335.     temp            : string[1];
  336.     
  337.   begin
  338.     if user_rec.noisy then
  339.       Write(com, BEL);
  340.     repeat
  341.       if mode = 'N' then
  342.         temp := Copy(prompt(pr+' [y/N] ? >', 1, 'ES'), 1, 1)
  343.       else
  344.         temp := Copy(prompt(pr+' [Y/n] ? >', 1, 'ES'), 1, 1);
  345.       ch := temp[1];
  346.     until (ch in ['Y', 'N', ' ']) or (not Online);
  347.     if ch = 'Y' then
  348.       ask := True
  349.     else if ch = 'N' then
  350.       ask := False
  351.     else if mode = 'Y' then
  352.       ask := True
  353.     else
  354.       ask := False;
  355.   end;
  356.   
  357.   
  358.   function test_bit(var num; bit_num : Integer) : Boolean;
  359.   
  360.   var
  361.     subject         : Integer absolute num;
  362.     dummy           : Integer;
  363.     
  364.   begin
  365.     dummy := subject;
  366.     dummy := dummy shr bit_num;
  367.     if Odd(dummy) then
  368.       test_bit := True
  369.     else
  370.       test_bit := False;
  371.   end;
  372.   
  373.   
  374.   procedure set_bit(var target; bit_num : Integer);
  375.   
  376.   var
  377.     subject         : Integer absolute target;
  378.     mask            : Integer;
  379.     
  380.   begin
  381.     mask := 1 shl bit_num;
  382.     subject := subject or mask;
  383.   end;
  384.   
  385.   
  386.   
  387.   procedure clear_bit(var target; bit_num : Integer);
  388.   
  389.   var
  390.     subject         : Integer absolute target;
  391.     mask            : Integer;
  392.     
  393.   begin
  394.     mask := not(1 shl bit_num);
  395.     subject := subject and mask;
  396.   end;
  397.   
  398.   
  399.   
  400.   procedure FindSect(var req : DosFileName; var drive : Str3; var found : Boolean);
  401.     { Find file section from requested name }
  402.     
  403.   var
  404.     This            : SectPtr;
  405.     sect_count      : Integer;
  406.     located         : Boolean;
  407.     
  408.   begin
  409.     This := SectBase;
  410.     located := False;
  411.     sect_count := 1;
  412.     while (not located) and (This <> nil) do
  413.       begin
  414.         located := (This^.SectName = req) or (strint(req) = sect_count);
  415.         if ((not cold) and (not((user_rec.access >= This^.SectAccs) or (test_bit
  416.           (user_rec.conf_flags, This^.SectConf))))) then
  417.           begin
  418.             Dec(sect_count);
  419.             located := False
  420.           end;
  421.         if located then
  422.           begin
  423.             drive := This^.SectDrive+':\';
  424.             req := This^.SectName
  425.           end;
  426.         This := This^.next;
  427.         Inc(sect_count);
  428.       end;
  429.     found := located;
  430.   end;
  431.   
  432.   
  433.   
  434.   function min(x, y : LongInt) : Integer;
  435.     { Return minimum of two integers }
  436.     
  437.   begin
  438.     if x < y then
  439.       min := x
  440.     else
  441.       min := y
  442.   end;
  443.   
  444.   
  445.   
  446.   function max(x, y : Integer) : Integer;
  447.     { Return greater of two integers }
  448.     
  449.   begin
  450.     if x > y then
  451.       max := x
  452.     else
  453.       max := y
  454.   end;
  455.   
  456.   
  457.   
  458.   function intstr(n, w : Integer) : Str10;
  459.     { Return a string value (width 'w')for the input integer ('n') }
  460.     
  461.   var
  462.     st              : Str10;
  463.     
  464.   begin
  465.     Str(n:w, st);
  466.     intstr := st
  467.   end;
  468.   
  469.   
  470.   
  471.   function strint(st : Str10)     : Integer;
  472.     { Convert string to integer }
  473.     
  474.   var
  475.     x, code         : Integer;
  476.     
  477.   begin
  478.     if st[1] = '+' then
  479.       Delete(st, 1, 1);
  480.     if st = '' then
  481.       code := 1
  482.     else
  483.       Val(st, x, code);
  484.     if code = 0 then
  485.       strint := x
  486.     else
  487.       strint := 0                 { Error, return with 0 }
  488.   end;
  489.   
  490.   
  491.   
  492.   function FormTAD(t : tad_array)  : StrTAD;
  493.     { Build printable string of current time and date }
  494.     
  495.   const
  496.     day : array[0..6] of string[6] = ('Sun', 'Mon', 'Tues', 'Wednes', 'Thurs', 'Fri', 'Satur');
  497.     month           : array[1..12] of string
  498.     [3]             = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
  499.     
  500.   var
  501.     i               : Integer;
  502.     line            : StrTAD;
  503.     
  504.     function zeller(day, month, year : Integer) : Integer;
  505.       { Compute the day of the week using Zeller's Congruence }
  506.       
  507.     var
  508.       century         : Integer;
  509.       
  510.     begin
  511.       if month > 2 then
  512.         month := month-2
  513.       else
  514.         begin
  515.           month := month+10;
  516.           year := Pred(year)
  517.         end;
  518.       century := year div 100;
  519.       year := year mod 100;
  520.       zeller := (day-1+((13*month-1) div 5)+(5*year div 4)+century div 4-2*century+1) mod 7
  521.     end;
  522.     
  523.     
  524.   begin
  525.     if (t[1] in [0..59]) and (t[2] in [0..23]) then
  526.       line := intstr(t[2], 2)+':'+intstr(t[1], 2)
  527.     else
  528.       line := '';
  529.     for i := 1 to Length(line) do
  530.       if line[i] = ' ' then
  531.         line[i] := '0';
  532.     if (t[3] in [1..31]) and (t[4] in [1..12]) and (t[5] in [0..99]) then
  533.       FormTAD := line+'  '+day[zeller(t[3], t[4], 1900+t[5])]+'day  '+intstr(t[3],
  534.         2)+'-'+month[t[4]]+'-'+intstr(t[5], 2)
  535.     else
  536.       FormTAD := 'No Date'
  537.   end;
  538.   
  539.   
  540.   procedure send_time(size : Integer; var mm, ss : Integer);
  541.     { Compute the file transfer time }
  542.     
  543.   var
  544.     tr_time         : Real;
  545.     
  546.   begin
  547.     tr_time := size*23.5/rate;    { Factor is empirically derived }
  548.     mm := Trunc(tr_time);
  549.     ss := Round(60.0*Frac(tr_time))
  550.   end;
  551.   
  552.   
  553.   
  554.   procedure timer(var time_on, time_left : Integer);
  555.     { Compute the time on and the time remaining to the current user }
  556.     
  557.   var
  558.     t               : tad_array;
  559.     give_extra      : Boolean;
  560.     
  561.   begin
  562.     GetTAD(t);
  563.     give_extra := False;
  564.     time_on := 60*(t[2]-login_t[2])+t[1]-login_t[1];
  565.     if time_on < 0 then
  566.       time_on := time_on+1440;
  567.     time_left := user_rec.limit+extra_time-time_on-user_rec.time_today;
  568.     if extra_time_sw then
  569.       begin
  570.         if ExtraTimeStart < ExtraTimeStop then
  571.           begin
  572.             if (t[2] > ExtraTimeStart) and (t[2] < ExtraTimeStop) then
  573.               give_extra := True;
  574.           end
  575.         else
  576.           begin
  577.             if (t[2] > ExtraTimeStart) and (t[2] < ExtraTimeStop+24) then
  578.               give_extra := True;
  579.             if (t[2] < ExtraTimeStart) and (t[2] < ExtraTimeStop) then
  580.               give_extra := True;
  581.           end;
  582.         if give_extra then
  583.           time_left := time_left+extra_time_val;
  584.       end;
  585.     if cmd_tail and (strint(ParamStr(1)) <> 99) and
  586.     (strint(ParamStr(1)) <> 98)
  587.     then
  588.       if time_left > (time_to_event-time_on) then
  589.         time_left := (time_to_event-time_on);
  590.   end;
  591.   
  592.   
  593.   
  594.   procedure mesg_insert(TypMsg : Byte);
  595.     { Insert message into linked list }
  596.     
  597.   var
  598.     This            : MesgPtr;
  599.     
  600.   begin
  601.     New(This);
  602.     if MesgBase = nil then
  603.       MesgBase := This
  604.     else
  605.       MesgLast^.next := This;
  606.     MesgLast := This;
  607.     MesgLast^.MesgNo := summ_rec.num;
  608.     MesgLast^.SummLoc := Pred(FilePos(summ_file));
  609.     MesgLast^.TypMsg := TypMsg;
  610.     MesgLast^.next := nil
  611.   end;
  612.   
  613.   
  614.   
  615.   procedure list(ch : Char);
  616.     { List a portion of the system message file }
  617.     
  618.   var
  619.     line_count      : Integer;
  620.     This            : SysmPtr;
  621.     
  622.   begin
  623.     This := SysmBase;
  624.     while (This <> nil) and (This^.key <> ch) do
  625.       This := This^.next;
  626.     if This^.key = ch then
  627.       begin
  628.         WriteLn(com);
  629.         Seek(sysm_file, Succ(This^.loc));
  630.         Read(sysm_file, sysm_rec);
  631.         line_count := 0;
  632.         if ch <> 'B' then
  633.           abort := False;
  634.         while (not brk) and (not EoF(sysm_file)) and (sysm_rec[1] <> ':') do
  635.           begin
  636.             WriteLn(com, sysm_rec);
  637.             Read(sysm_file, sysm_rec);
  638.             if (user_rec.lines <> 99) and (ch <> 'W') and (ch <> 'F') then
  639.               begin
  640.                 Inc(line_count);
  641.                 if line_count mod user_rec.lines = 0 then
  642.                   pause
  643.               end
  644.           end
  645.       end
  646.   end;
  647.   
  648.   
  649.   
  650.   procedure Write_status_line;
  651.   
  652.   var
  653.     Str             : StrTAD;
  654.     date            : tad_array;
  655.     
  656.   begin
  657.     date := user_rec.laston;
  658.     Str := intstr(date[4], 2)+'/'+intstr(date[3], 2)+'/'+intstr(date[5], 2);
  659.     putstat(user_rec.fn+' '+user_rec.ln+'  '+user_rec.cy+', '+user_rec.st+'   Phone: '+user_rec.ph
  660.       , ' Last on: '+Str+'  Access: '+intstr(user_rec.access,
  661.         1)+'  On today: '+intstr((time_on+user_rec.time_today),
  662.           1)+'  Time Limit: '+intstr(user_rec.limit, 1)+'  '+intstr(rate, 1)+' Baud');
  663.   end;
  664.   
  665.   
  666.   
  667.   procedure caps_to_mixed(var full_name : StrStd);
  668.   
  669.   var
  670.     i, temp         : Integer;
  671.     
  672.   begin
  673.     for i := 2 to Length(full_name) do
  674.       if full_name[Pred(i)] <> Chr($20) then
  675.         full_name[i] := LoCase(full_name[i]);
  676.     temp := Pos(' Mc', full_name);
  677.     if temp <> 0 then
  678.       full_name[temp+3] := Upcase(full_name[temp+3]);
  679.   end;
  680.   
  681.   
  682.   procedure ScrollOn;
  683.   
  684.   begin
  685.     if fconsole then
  686.       begin
  687.         Assign(lst, 'CON');
  688.         Rewrite(lst);
  689.         Write(lst, #27, '[>9;23z');
  690.         Close(lst);
  691.       end
  692.     else
  693.       ClrScr;
  694.   end;
  695.   
  696.   
  697.   procedure ScrollOff;
  698.   
  699.   begin
  700.     if fconsole then
  701.       begin
  702.         Assign(lst, 'CON');
  703.         Rewrite(lst);
  704.         Write(lst, #27, '[>9;25z');
  705.         Close(lst);
  706.       end;
  707.   end;
  708.   
  709.   
  710.   {$F+}
  711.   procedure NewExit; {$F-}
  712.   
  713.   var
  714.     LogStr          : string[72];
  715.     
  716.   begin
  717.     SetSect(HomName);
  718.     Assign(temp_file, 'TPBUP.BB#');
  719.     Erase(temp_file);
  720.     if ErrorAddr <> nil then
  721.       begin
  722.         LogStr := ' @ '+HexPtr(ErrorAddr);
  723.         log(10, LogStr);
  724.         Str(ExitCode, LogStr);
  725.         LogStr := 'Runtime '+LogStr;
  726.         log(10, LogStr);
  727.         ErrorAddr := nil;
  728.         mdhangup;
  729.       end;
  730.     ExitCode := NetMsgEntr+EchoMsgEntr;
  731.     ExitProc := ExitSave;
  732.   end { NewExit } ;
  733.   
  734.   
  735.   function greg_to_jul(day, mon, yr : Integer) : Real;
  736.     { Convert from Gregorian date to Julian }
  737.     
  738.   var
  739.     i               : Integer;
  740.     
  741.   begin
  742.     i := (mon-14) div 12;
  743.     greg_to_jul := day-32075+367*(mon-2-12*i) div 12-3*(yr+6800+i) div 400+365.25*(yr+6700+i)
  744.   end;
  745.   
  746.   
  747.   
  748.   procedure check_time;
  749.     {checks time on system and time left}
  750.     
  751.   begin
  752.     timer(time_on, time_left);
  753.     if time_left <= 0 then
  754.       begin
  755.         WriteLn(com, 'Access time expired.  Please call back tomorrow.', BEL, BEL, BEL);
  756.         Delay((9600 div rate)*100);
  757.         remote_online := False;
  758.         mdhangup;
  759.       end
  760.     else if (time_left <= 5) and (time_left <> last_time_left) then
  761.       begin
  762.         WriteLn(com, 'Less than ', time_left, ' minutes of access time left.', BEL);
  763.         last_time_left := time_left;
  764.         WriteLn(com);
  765.       end;
  766.   end;
  767.   
  768.   
  769.   
  770.   {$F+}
  771.   procedure UserEventCheck(EventNo, KbdFlagInfo : Word);
  772.     {Background process called at every keypressed check}
  773.     {This routine performs automatic word wrap if needed}
  774.     
  775.   const
  776.     LastWhereX : Integer = 0;
  777.     overflow : string = '';
  778.     
  779.   var
  780.     next_inpstr, CharStr : string;
  781.     ThisWhereX, i   : Integer;
  782.     
  783.   begin                           {UserEventCheck}
  784.     if overflow <> '' then
  785.       begin
  786.         next_inpstr := StuffKey(overflow);
  787.         overflow := next_inpstr;
  788.       end
  789.     else
  790.       begin
  791.         ThisWhereX := WhereX;
  792.         if (ThisWhereX = 76) and (ReadCharAtCursor = ' ') then
  793.           if ThisWhereX > LastWhereX then
  794.             begin
  795.               FlushKey;
  796.               i := 0;
  797.               CharStr := LeftArrow;
  798.               repeat
  799.                 Inc(i);
  800.                 next_inpstr := StuffKey(CharStr);
  801.                 if next_inpstr <> '' then
  802.                   overflow := overflow+next_inpstr;
  803.                 GoToXY(Pred(WhereX), WhereY);
  804.               until ReadCharAtCursor = ' ';
  805.               if i < 2 then
  806.                 next_inpstr := CR
  807.               else
  808.                 next_inpstr := CR+DelKey+EndKey;
  809.               next_inpstr := StuffKey(next_inpstr);
  810.               if next_inpstr <> '' then
  811.                 overflow := overflow+next_inpstr;
  812.             end;
  813.         LastWhereX := ThisWhereX;
  814.         if WhereY <> 2 then
  815.           FastWrite('   '+DispName, 2, 47, 13);
  816.       end;
  817.   end;                            {UserEventCheck}
  818.   
  819.   
  820.   procedure put_recs;
  821.   
  822.   begin
  823.     Assign(sort_file, 'SORT.TMP');
  824.     Reset(sort_file);
  825.     with sort_rec do
  826.       begin
  827.         while (not EOF(sort_file)) do
  828.           begin
  829.             ReadLn(sort_file, first);
  830.             ReadLn(sort_file, second);
  831.             SortRelease(sort_rec);
  832.           end;
  833.       end;
  834.     Close(sort_file);
  835.     Erase(sort_file);
  836.   end;
  837.   
  838.   
  839.   procedure get_recs;
  840.   
  841.   begin
  842.     while (not SortEOS) do
  843.       begin
  844.         SortReturn(sort_rec);
  845.         with sort_rec do
  846.           begin
  847.             WriteLn(dir_file, first);
  848.             WriteLn(dir_file, second);
  849.             WriteLn(dir_file);
  850.           end;
  851.       end;
  852.   end;
  853.   
  854.   
  855.   function less_rec(var x, y : sort_typ) : Boolean;
  856.   
  857.   begin
  858.     less_rec := ((x.first) < (y.first))
  859.   end;
  860.   {$F-}
  861.   
  862.   
  863. end.                              { of CORE1.PAS }
  864. 
  865.